// services/mock_api.dart
import 'dart:convert';
import 'package:flutter/services.dart';
import 'package:music_app/models/home_model.dart';

class MockApi {
  /// 通用 JSON 加载方法
  static Future<Map<String, dynamic>> _loadJson(String path) async {
    try {
      // await Future.delayed(const Duration(milliseconds: 200));
      final jsonString = await rootBundle.loadString(path);
      return json.decode(jsonString) as Map<String, dynamic>;
    } catch (e) {
      throw Exception('Failed to load JSON: $path');
    }
  }

  /// 各个页面的具体请求方法
  static Future<HomeModel> fetchHomeData() async {
    final jsonData = await _loadJson('assets/mock/play_list.json');
    return HomeModel.fromJson(jsonData);
  }

  // 歌单详情
  static Future<Map<String, dynamic>> fetchPlayList() async {
    final jsonData = await _loadJson('assets/mock/play_list.json');
    return jsonData;
  }

  // 推荐歌单
  static Future<Map<String, dynamic>> fetchRecommendSongList() async {
    final jsonData = await _loadJson('assets/mock/recommend_song_list.json');
    return jsonData;
  }

  // 每日推荐
  static Future<Map<String, dynamic>> fetchRecommendSongs() async {
    final jsonData = await _loadJson('assets/mock/recommend_songs.json');
    return jsonData;
  }

  // 用户信息
  static Future<Map<String, dynamic>> fetchUser() async {
    final jsonData = await _loadJson('assets/mock/user.json');
    return jsonData;
  }
  // 添加更多页面请求方法...
}
